package com.huzz.controller;

import com.huzz.entity.SysDepartment;
import com.huzz.model.SysDepartmentCreateModel;
import com.huzz.model.SysDepartmentQueryModel;
import com.huzz.model.SysDepartmentUpdateModel;
import com.huzz.service.ISysDepartmentService;
import com.huzz.util.body.JsonResult;
import com.huzz.util.body.ResultTool;
import com.huzz.util.log.Log;
import com.huzz.util.log.LogStarter;
import com.huzz.util.log.Operate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* 系统部门-业务模块
*
* @author 童年的纸飞机
* @since 2023-06-07 11:25
*/
@Slf4j
@LogStarter("系统部门模块")
@RestController
@RequestMapping("/api/SysDepartment")
@Api(value = "系统部门模块 API", tags = {"系统部门模块 API"})
public class SysDepartmentController {

    @Autowired
    private ISysDepartmentService sysDepartmentService;

    @Log(name = "根据id查询系统部门", operateType = Operate.SELECT)
    @ApiOperation("根据id查询系统部门")
    @GetMapping("/findSysDepartmentById")
    public JsonResult<SysDepartment> findSysDepartmentById(@RequestParam Integer id) {
        return ResultTool.success(sysDepartmentService.getSysDepartmentById(id));
    }

    @Log(name = "新建系统部门", operateType = Operate.INSERT)
    @ApiOperation("新建系统部门")
    @PostMapping("/createSysDepartment")
    public JsonResult createSysDepartment(@Validated @RequestBody SysDepartmentCreateModel model) {
        return sysDepartmentService.createSysDepartment(model) ? ResultTool.success("新建成功") : ResultTool.fail("新建失败");
    }

    @Log(name = "更新系统部门", operateType = Operate.UPDATE)
    @ApiOperation("更新系统部门")
    @PutMapping("/updateSysDepartment")
    public JsonResult updateSysDepartment(@Validated @RequestBody SysDepartmentUpdateModel model) {
        return sysDepartmentService.updateSysDepartment(model) ? ResultTool.success("更新成功") : ResultTool.fail("更新失败");
    }

    @Log(name = "根据ID删除系统部门", operateType = Operate.DELETE)
    @ApiOperation("根据ID删除系统部门")
    @DeleteMapping("/removeSysDepartmentById")
    public JsonResult removeSysDepartmentById(@RequestParam Integer id) {
        return sysDepartmentService.deleteSysDepartmentById(id) ? ResultTool.success("删除成功") : ResultTool.fail("删除失败");
    }

    @Log(name = "查询树型系统部门", operateType = Operate.SELECT)
    @ApiOperation("查询树型系统部门")
    @GetMapping("/querySysDepartmentTree")
    public JsonResult querySysDepartmentTree(@Validated SysDepartmentQueryModel model) {
        return ResultTool.success(sysDepartmentService.selectSysDepartmentTree(model));
    }

    @Log(name = "查询系统部门列表", operateType = Operate.SELECT)
    @ApiOperation("查询系统部门列表")
    @GetMapping("/querySysDepartmentList")
    public JsonResult querySysDepartmentList(@Validated SysDepartmentQueryModel model) {
        return ResultTool.success(sysDepartmentService.selectSysDepartmentList(model));
    }

    @Log(name = "导出系统部门", operateType = Operate.EXPORT, saveResResult = false)
    @ApiOperation("导出系统部门列表")
    @GetMapping("/exportSysDepartmentExcel")
    public void exportSysDepartmentExcel(HttpServletRequest request, HttpServletResponse response, @Validated SysDepartmentQueryModel model) {
        sysDepartmentService.exportSysDepartmentExcel(request, response, model);
    }

}




































